package it.unibo.contact.EnvSystem;

import it.unibo.is.interfaces.IMessage;
import it.unibo.is.interfaces.platforms.IAcquireOneReply;
import it.unibo.is.interfaces.platforms.IMessageAndContext;

public class Process2 extends Process2Support {

	public Process2() throws Exception 
	{
		super();
		value = "valueProcess2";
	}

	@Override
	public void doJob() throws Exception 
	{
		hl_process_ask_observeEnvironment_environment("");

		while(true)
		{
			IMessage mess = selectOneInput();
			showMsg("Event Received: " + mess.msgContent());
			String key =  mess.msgContent();

			if(key.equals("keyProcess"))
			{
				IAcquireOneReply reply = hl_process_demand_getData_environment(key);
				MyClass object = (MyClass)fromString(reply.acquireReply().msgContent());
				showMsg("dato1: " + object.getDato1());
				showMsg("Elemento 1 lista: " + object.getList().get(0));
				showMsg("dato1 Annidato: " + object.getObject2().getDato1());
			}
			else if(key.equals("otherKey"))
			{
				IAcquireOneReply reply = hl_process_demand_getData_environment(key);
				String value = (String) fromString(reply.acquireReply().msgContent());
				showMsg("value: " + value);
			}
			else if(key.equals("otherKey2"))
			{
				IAcquireOneReply reply = hl_process_demand_getData_environment(key);
				int value = (Integer) fromString(reply.acquireReply().msgContent());
				showMsg("value: " + value);
			}
		}
	}

}
